package leetcode.list_problem;

/**
 * 剑指 Offer 24. 反转链表
 * https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/
 */
public class ReverseLinkedList {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null){//退出条件
            return head;
        }
        ListNode next = head.next;
        ListNode node = reverseList(head.next);//这个递归及其巧妙多看看他的head不是node
        next.next = head;//这里的head指向哪里一定要注意，画图理解一下
        head.next = null;
        return node;
    }
}
